package com.jsoft.utils;

import java.util.List;

/**
 * 分页查询
 * @author jsoft
 */
public class PageHelper<T> {

    // 当前页
    private int currentPage = 1;
    // 每页显示的条数
    private int pageSize = 2;
    // 总记录数
    private long total;

    // 起始位置
    private int start;

    // 最后一页
    private int lastPage;

    // 显示的数据
    private List<T> data;

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public void setLastPage(int lastPage) {
        this.lastPage = lastPage;
    }

    public void setTotal(long total) {
        this.total = total;
        // 计算总页数
        this.lastPage = (int)Math.ceil((double)total / pageSize);
    }

    public int getStart() {
        return (currentPage - 1) * pageSize;
    }

    public int getLastPage() {
        return lastPage;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
}
